<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>资金到位 - 分成资金 - 添加</title>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/easyui/themes/default/easyui.css" />
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/easyui/themes/icon.css" />
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/buttons.css" />
    <script type="text/javascript" src="${pageContext.request.contextPath}/easyui/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-form.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/easyui/datagrid-detailview.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/easyui/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/util/jquery.cookie.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/YMLib.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/YWLib.js"></script>
    <style type="text/css">
        .table{border: 1px solid #FFE7BA;}
        .table tr{border: 1px solid #FFE7BA;}
        .table tr td{border: 1px solid #FFE7BA;}
        .table tr td input{width: 50px;}
        .table1{border: 1px solid #FFE7BA;}
        .table1 tr{border: 1px solid #FFE7BA;}
        .table1 tr td{border: 1px solid #FFE7BA;}
    </style>
    <script type="text/javascript">
        function loadWhBmbmShNew(id, xmbm, xmnf) {
            $('#' + id).combobox({
                url : '/jxcsxm/shares/getShareTreeByName.do?xmbm='
                    + encodeURI(encodeURI(xmbm))+"&xmnf="+xmnf,
                valueField : 'bmid',
                textField : 'name',
                panelHeight:'auto',
                editable:false,
                multiple:false
            });
        }

        function search() {

            var params = {
                'gydwdm': $.cookie("unit"),
                'jhxdwh':$("#jhxdwh").combo('getValue')
            };
            $.ajax({
                type:'post',
                async:false,
                url:'/jxcsxm/shares/queryZjByGydwdm.do',
                data:params,
                dataType:'json',
                success:function(data){
                    if (data.ztz == 0) {
                        alert('没有可以分配的计划资金！');
                        return;
                    }
                    $("#funds_num").text(data.ztz);
                }
            });
        }

        $(function () {

            $("#nf1").combobox({onSelect:function(record){
                 // loadWhBmbmShNew('jhxdwh', $("#nf1").combobox('getValue'));
                 loadWhBmbmShNew('jhxdwh', parent.parent.YMLib.Var.xmbm, $("#nf1").combobox('getValue'));
             }});

            loadWhBmbmShNew('jhxdwh', parent.parent.YMLib.Var.xmbm, $("#nf1").combobox('getValue'));

            loadBmbm('nf1','项目年份',new Date().getFullYear());

            getFwqTime("dwyf");

            var gydw=$.cookie("unit");
            if(gydw=="36"){
                loadChildGydw("11101360000");
            }else{
                loadChildGydw(gydw);
            }
        });

        function sumDfzc(){
            var tr = $("tr[name='"+$.cookie("unit")+"']");
            $.each(tr,function(index,item){
                var inputList = $("#"+item.id+" input");
                var dszc1=0;var qxzc1=0;var qtzc1=0;
                // dfzc1=$(inputList[3]).val()==""?0:$(inputList[3]).val();
                dszc1=parseFloat($(inputList[7]).val()==""?0:$(inputList[7]).val());
                qxzc1=parseFloat($(inputList[8]).val()==""?0:$(inputList[8]).val());
                qtzc1=parseFloat($(inputList[9]).val()==""?0:$(inputList[9]).val());
                $(inputList[3]).val(dszc1+qxzc1+qtzc1);
            });

            // $('#dfzc').val(parseFloat($('#dszc').val() === "" ?0:$('#dszc').val())
            // 		+parseFloat($('#qxzc').val() === "" ?0:$('#qxzc').val())
            // 		+parseFloat($('#qtzc').val() === "" ?0:$('#qtzc').val()) );

        }

        function loadChildGydw(gydw){
            $.ajax({
                type:'post',
                async:false,
                url:'/jxcsxm/shares/queryChildGydw.do',
                data:'gydw='+gydw,
                dataType:'json',
                success:function(data){
                    $.each(data,function(index,item){
                        if(item.sfds=='1'){
                            $('#zjdw_table_tbody').append('<tr name="'+$.cookie("unit")+'" id="'+item.id+'">' +
                                '<td align="center">'+item.name+'</td>' +
                                '<td align="left" style="padding-left:10px;"><input type="number" width="60"/><font color="red"></font></td>' +
                                '<td align="left" style="padding-left:10px;"><input type="number" width="60" /><font color="red"></font></td>' +
                                '<td align="left" style="padding-left:10px;"><input type="number" width="60" /><font color="red"></font></td>' +
                                '<td align="left" style="padding-left:10px;"><input type="number" width="60" readonly="readonly" /><font color="red"></font>' +
                                '<input type="hidden" value="'+item.parent+'"/>' +
                                '<input type="hidden" value="'+item.sfds+'"/>' +
                                '<input type="hidden" value="'+item.sftj+'"/></td>' +
                                '<td align="left" style="padding-left:10px;"><input type="number" width="60" oninput="sumDfzc()" /><font color="red"></font></td>' +
                                '<td align="left" style="padding-left:10px;"><input type="number" width="60" oninput="sumDfzc()" /><font color="red"></font></td>' +
                                '<td align="left" style="padding-left:10px;"><input type="number" width="60" oninput="sumDfzc()" /><font color="red"></font></td>' +
                                '</tr>');
                        }else{
                            if(item.sftj=='1'){
                                $('#zjdw_table_tbody').append('<tr class="'+item.parent+'" name="'+$.cookie("unit")+'" id="'+item.id+'">' +
                                    '<td align="center">'+item.name+'</td>' +
                                    '<td align="left" style="padding-left: 10px;"><input type="number" width="60" /><font color="red"></font></td>' +
                                    '<td align="left" style="padding-left: 10px;"><input type="number" width="60" /><font color="red"></font></td>' +
                                    '<td align="left" style="padding-left: 10px;"><input type="number" width="60" /><font color="red"></font></td>' +
                                    '<td align="left" style="padding-left: 10px;"><input type="number" width="60" readonly="readonly" /><font color="red"></font>' +
                                    '<input type="hidden" value="'+item.parent+'"/>' +
                                    '<input type="hidden" value="'+item.sfds+'"/>' +
                                    '<input type="hidden" value="'+item.sftj+'"/></td>' +
                                    '<td align="left" style="padding-left: 10px;"><input type="number" width="60" oninput="sumDfzc()" /><font color="red"></font></td>' +
                                    '<td align="left" style="padding-left: 10px;"><input type="number" width="60" oninput="sumDfzc()" /><font color="red"></font></td>' +
                                    '<td align="left" style="padding-left: 10px;"><input type="number" width="60" oninput="sumDfzc()" /><font color="red"></font></td>' +
                                    '</tr>');
                            }else{
                                $('#zjdw_table_tbody').append('<tr name="'+$.cookie("unit")+'" id="'+item.id+'"><td align="center">'+item.name+'</td>' +
                                    '<td align="left" style="padding-left: 10px;"><input type="number" width="60" /><font color="red"></font></td>' +
                                    '<td align="left" style="padding-left: 10px;"><input type="number" width="60" /><font color="red"></font></td>' +
                                    '<td align="left" style="padding-left: 10px;"><input type="number" width="60" /><font color="red"></font></td>' +
                                    '<td align="left" style="padding-left: 10px;"><input type="number" width="60" readonly="readonly" /><font color="red"></font>' +
                                    '<input type="hidden" value="'+item.parent+'"/>' +
                                    '<input type="hidden" value="'+item.sfds+'"/>' +
                                    '<input type="hidden" value="'+item.sftj+'"/></td>' +
                                    '<td align="left" style="padding-left: 10px;"><input type="number" width="60" oninput="sumDfzc()" /><font color="red"></font></td>' +
                                    '<td align="left" style="padding-left: 10px;"><input type="number" width="60" oninput="sumDfzc()" /><font color="red"></font></td>' +
                                    '<td align="left" style="padding-left: 10px;"><input type="number" width="60" oninput="sumDfzc()" /><font color="red"></font></td>' +
                                    '</tr>');
                            }
                        }
                    });
                }
            });
        }

        function jssjzj(parent){
            var cgs=0,rys=0,ttc=0,dfzc=0,dszc=0,qxzc=0,qtzc=0;
            var tr = $("tr[class='"+parent+"']");
            $.each(tr,function(index,item){
                var inputList = $("#"+item.id+" input");
                cgs=accAdd(cgs,$(inputList[0]).val()==""?0:$(inputList[0]).val());
                rys=accAdd(rys,$(inputList[1]).val()==""?0:$(inputList[1]).val());
                ttc=accAdd(ttc,$(inputList[2]).val()==""?0:$(inputList[2]).val());
                dfzc=accAdd(dfzc,$(inputList[3]).val()==""?0:$(inputList[3]).val());

                dszc=accAdd(dszc,$(inputList[7]).val()==""?0:$(inputList[7]).val());
                qxzc=accAdd(qxzc,$(inputList[8]).val()==""?0:$(inputList[8]).val());
                qtzc=accAdd(qtzc,$(inputList[9]).val()==""?0:$(inputList[9]).val());
            });
            var inputList = $("#"+parent+" input");
            $(inputList[0]).val(cgs);
            $(inputList[1]).val(rys);
            $(inputList[2]).val(ttc);
            $(inputList[3]).val(dfzc);

            $(inputList[7]).val(dszc);
            $(inputList[8]).val(qxzc);
            $(inputList[9]).val(qtzc);
        }

        function save() {

            if($('#jhxdwh').combo("getValue")==""){alert("请选择计划下达文号");return;}

            var ztz = $("#funds_num").text();
            if (ztz == 0) {
                alert("请点击查询所剩资金！");return;
            }

            if ($("#tbsj").datebox("getValue") == "" || $("#tbsj").datebox("getValue") == null) {
                alert("请选择填报时间！");return;
            }

            var zj = params($.cookie("unit"));

            console.log(zj);

            if (parseInt(zj.ztz) == 0) {
                alert("请认真填写！");
                return;
            }

            if (parseFloat(zj.ztz) > parseFloat(ztz)) {
                alert('所填总补助不能大于计划总补助，请认真核对');
                return;
            }

            loadjzt();

            $.ajax({
                type:'post',
                url:'/jxcsxm/shares/insertOrUpdateShqx.do',
                data:zj,
                dataType:'json',
                success:function(data){
                    disLoadjzt();
                    alert("保存成功！");
                    parent.$("#grid").datagrid('reload');
                    parent.getdwTj();
                    parent.parent.$("#grid").datagrid('reload');
                    parent.parent.loadTj();
                    closeWindow();
                }
            });
        }

        function params(name){
            var zj = {
                gydwdm: "", parent: "", dwyf: "",
                cgs1: "", rys1: "", ttc1: "", // 车购税  燃油税  厅统筹
                dfzc1: "", dszc1: "", qxzc1: "", qtzc1:"", // 地方自筹 财政自筹 县区财政  其他自筹
                ztz1:"", bd:"", jhxdwh:"", xmdj:"",
                nf:"", tbsj:"",ztz:"", gydw: ""
            };
            var tr = $("tr[name='"+name+"']");
            var ztz1=0;var cgs1=0;var rys1=0;
            var ttc1=0;var dfzc1=0;var dszc1=0;
            var qxzc1=0;var qtzc1=0;
            var ztz = 0;
            $.each(tr, function (index, item) {
                var inputList = $("#"+item.id+" input");
                var trList = $("#"+item.id+" td");
                if (index == 0) {
                    zj.gydwdm = item.id;
                    zj.gydw = $(trList[0]).text();
                    zj.parent = $(inputList[4]).val();
                    zj.dwyf = $("#dwyf").combo('getValue');
                    cgs1 = $(inputList[0]).val() == "" || $(inputList[0]).val() == null ?
                        0 : parseFloat($(inputList[0]).val()); // 车购税
                    rys1 = $(inputList[1]).val() == "" || $(inputList[1]).val() == null ?
                        0 : parseFloat($(inputList[1]).val()); // 燃油税
                    ttc1 = $(inputList[2]).val() == "" || $(inputList[2]).val() == null ?
                        0 : parseFloat($(inputList[2]).val()); // 厅统筹
                    dszc1 = $(inputList[7]).val() == "" || $(inputList[7]).val() == null ?
                        0 : parseFloat($(inputList[7]).val()); // 地方财政
                    qxzc1 = $(inputList[8]).val() == "" || $(inputList[8]).val() == null ?
                        0 : parseFloat($(inputList[8]).val()); // 县区财政
                    qtzc1 = $(inputList[9]).val() == "" || $(inputList[9]).val() == null ?
                        0 : parseFloat($(inputList[9]).val()); // 其他自筹
                    dfzc1 = dszc1 + qxzc1 + qtzc1;
                    zj.cgs1 = cgs1;zj.rys1 = rys1;zj.ttc1 = ttc1;
                    zj.dfzc1 = dfzc1;zj.dszc1 = dszc1;zj.qxzc1 = qxzc1;
                    zj.qtzc1 = qtzc1;
                    ztz1 = cgs1 + rys1 + ttc1 + dfzc1;
                    zj.ztz1 = ztz1;
                    ztz = ztz1;
                    zj.bd = "没有";
                    zj.xmdj = "农村";
                    zj.jhxdwh = $("#jhxdwh").combo('getValue');
                    zj.nf = $("#nf1").combo('getValue');
                    zj.tbsj = $("#tbsj").datebox("getValue");
                } else {
                    zj.gydwdm += "," + item.id;
                    zj.gydw += "," + $(trList[0]).text();
                    zj.parent += "," + $(inputList[4]).val();
                    zj.dwyf += "," + $("#dwyf").combo('getValue');
                    cgs1 = $(inputList[0]).val() == "" || $(inputList[0]).val() == null ?
                        0 : parseFloat($(inputList[0]).val()); // 车购税
                    rys1 = $(inputList[1]).val() == "" || $(inputList[1]).val() == null ?
                        0 : parseFloat($(inputList[1]).val()); // 燃油税
                    ttc1 = $(inputList[2]).val() == "" || $(inputList[2]).val() == null ?
                        0 : parseFloat($(inputList[2]).val()); // 厅统筹
                    dszc1 = $(inputList[7]).val() == "" || $(inputList[7]).val() == null ?
                        0 : parseFloat($(inputList[7]).val()); // 地方财政
                    qxzc1 = $(inputList[8]).val() == "" || $(inputList[8]).val() == null ?
                        0 : parseFloat($(inputList[8]).val()); // 县区财政
                    qtzc1 = $(inputList[9]).val() == "" || $(inputList[9]).val() == null ?
                        0 : parseFloat($(inputList[9]).val()); // 其他自筹
                    dfzc1 = dszc1 + qxzc1 + qtzc1;
                    zj.cgs1 += "," + cgs1;
                    zj.rys1 += "," + rys1;
                    zj.ttc1 += "," + ttc1;
                    zj.dfzc1 += "," + dfzc1;
                    zj.dszc1 += "," + dszc1;
                    zj.qxzc1 += "," + qxzc1;
                    zj.qtzc1 += "," + qtzc1;
                    ztz1 = cgs1 + rys1 + ttc1 + dfzc1;
                    ztz += ztz1;
                    zj.ztz1 += "," + ztz1;
                    zj.bd += "," + "没有";
                    zj.xmdj += "," + "农村";
                    zj.jhxdwh += "," + $("#jhxdwh").combo('getValue');
                    zj.nf += "," + $("#nf1").combo('getValue');
                    zj.tbsj += "," + $("#tbsj").datebox("getValue");
                }
            });
            zj.ztz = ztz;
            return zj;
        }
    </script>
</head>
<body>
    <div style="text-align: left;font-size: 12px;margin: 0px;width:99%;">
        <table width="99%" border="0" style="margin-top: 1px; margin-left: 1px;" cellspacing="0" cellpadding="0">
            <tr>
                <td>
                    <div align="center">
                        <table class="table1" cellpadding="0" cellspacing="0" width="800">
                            <tr align='center' height="28">
                                <td width="100">年份</td>
                                <td  align="left" style="padding-left: 10px;" width="100">
                                    <input type="text" class='easyui-combobox' id='nf1' style="width: 145px;">
                                <td width="100">计划下达文号</td>
                                <td align="left" style="padding-left: 10px;" width="100"><input type='text' id='jhxdwh'style="width: 145px;"></td>
                            </tr>

                            <tr align='center' height="28">
                                <td width="100">到位月份</td>
                                <td align="left" style="padding-left: 10px;" width="100">
                                    <input type="text" class='easyui-combobox' id='dwyf' style="width: 120px;">
                                <td align="left" style="padding-left: 10px;" colspan="2">
                                    <input value=" 查询  " onclick="search()" style="text-align: center;" type="button"/><font color="red" id="funds_id">
                                *选择计划下达文号点击查询自动计算剩余资金[<i id="funds_num">0</i>万元]</font>
                                </td>
                            </tr>
                            <tr align='center' height="28">
                                <td width="100">填报时间</td>
                                <td align="left" style="padding-left: 10px;" width="100">
                                    <input type='text' class='easyui-datebox' id='tbsj'style="width: 145px;" readonly="readonly">
                                </td>
                                <td width="100"></td>
                                <td align="left" style="padding-left: 10px;" width="100">
                                </td>
                            </tr>
                        </table>
                        <table id="zjdw_table" width="800" class="table" cellpadding="0" cellspacing="0">
                            <tr align='center' height="28">
                                <td>单位名称</td>
                                <td>车购税(万元)</td>
                                <td>燃油税(万元)</td>
                                <td>厅统筹(万元)</td>
                                <td>地方自筹(万元)</td>
                                <td>地市财政自筹(万元)</td>
                                <td>区县财政自筹(万元)</td>
                                <td>其他自筹(万元)</td>
                            </tr>
                            <tbody id="zjdw_table_tbody"></tbody>
                        </table>
                        <table width="600">
                            <tr align="center">
                                <td>
                                    <input value=" 保  存  " onclick="save()" style="text-align: center;" type="button"/>
                                </td>
                            </tr>
                        </table>
                    </div>
                </td>
            </tr>
        </table>
    </div>
</body>
</html>
